package com.example.hospitaldemo.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.hospitaldemo.entity.Zhiliaoshi;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 床位表 Mapper 接口
 * </p>
 *
 * @author 张三
 * @since 2024-12-16
 */
public interface ZhiliaoshiMapper extends BaseMapper<Zhiliaoshi> {
    /**
     * 查询所有床位时，关联查询对应的科室
     *
     * ${ew.customSqlSegment} 固定的，动态拼接条件语句
     * @param page         分页查询条件
     * @param queryWrapper 实体对象封装操作类（可以为 null）
     * @return
     * @param <P>
     */
    @Select("select * from zhiliaoshi ${ew.customSqlSegment}")
    @Results({
            @Result(column = "ward_id",property = "wardId"),
            @Result(column = "ward_id",property = "ward",
                    //一对一的关联查询
                    one = @One(select = "com.example.hospitaldemo.mapper.WardMapper.selectById")),
    })
    @Override
   <P extends IPage<Zhiliaoshi>> P selectPage(P page, @Param("ew") Wrapper<Zhiliaoshi> queryWrapper);

    /**
     *      应用于入院登记
     */
    @Select("select  *  from zhiliaoshi where ward_id=#{wardId} and state=0")
    List<Zhiliaoshi> getZhiliaoshiInWard(Integer wardId);


    /**
     *      应用于出院登记
     */
    @Select("select * from zhiliaoshi where id=#{id}")
    @Results({
            @Result(column = "ward_id",property = "wardId"),
            @Result(column = "ward_id",property = "ward",
                    one = @One(select = "com.example.hospitaldemo.mapper.WardMapper.selectById"))
    })
    @Override
    Zhiliaoshi selectById(Serializable id);
}
